package com.hdu.hot100.tree;

import com.sun.org.apache.regexp.internal.REUtil;

public class lc98 {

    public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode() {
        }

        TreeNode(int val) {
            this.val = val;
        }

        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }

    class Solution {

        boolean ans = true;
        TreeNode prev = null;

        public boolean isValidBST(TreeNode root) {
            f(root);
            return ans;
        }

        void f(TreeNode root) {
            if (root == null) return;
            f(root.left);
            if (prev != null) {
                if (prev.val >= root.val) {
                    ans = false;
                    return;
                }
            }
            prev = root;
            f(root.right);
        }
    }

}
